package com.qulai.quartz.task;

import com.qulai.common.utils.http.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

import static com.qulai.common.utils.http.HttpUtils.*;

/**
 * 定时任务调度
 *
 * @author ruoyi
 */
@Component("hunanTask")
public class HunanTask {

    @Autowired
    private ReplacePythonDef replacePythonDef;

    private static final Logger log = LoggerFactory.getLogger(HunanTask.class);

    //更新云仓价格库存
    public void update_gg_price_quantity() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_gg_price_quantity, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    //更新云仓产品信息
    public void update_gg_product_info() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_gg_product_info, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
    //更新StarHome价格库存
    public void update_sh_price_quantity() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_sh_price_quantity, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }



    // 打标签
    public void amazon_us_tag() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(amazon_us_to_tag, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    // 打流量词
    public void amazon_us_search_words() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(amazon_us_to_search_words, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    //更新xl价格库存或新品
    public void update_xl_price_quantity() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_xl_price_quantity, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }


    //制作表格
    public void amazon_us_xlsm_to_upload(String upload_id) {
        Map<String, Object> params = new HashMap<>();
        params.put("upload_id", upload_id);
        try {
            HttpUtils.sendPostToPython(amazon_us_to_upload, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    //删除三天前上传失败的记录

    public void amazon_us_record_fail_delete(String directoryPath, String intervalDay,  String deleteStr) {

        replacePythonDef.clearFailUploadRecordOrAddRecord(directoryPath, Integer.parseInt(intervalDay), deleteStr);
    }


    //追加新品,包括s3和ocr
    public void basic_append_new_product() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_basic_append_new_product, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    //更新doba库存和价格
    public void update_db_price_quantity() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_db_price_quantity, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    //更新doba的运费
    public void update_db_ship_fee() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_db_ship_fee, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    //删除货源下架了的sku
    public void amazon_us_del_sku() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(amazon_us_sku_del, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }


    //更新赛盈价格库存
    public void update_sy_price_quantity() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_sy_price_quantity, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }


    //更新赛盈价格库存
    public void update_amazon_us_quantity_price_to_txt() {
        Map<String, Object> params = new HashMap<>();
        params.put("version", "1.0");
        try {
            HttpUtils.sendPostToPython(flush_update_price_quantity_to_txt, params);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }


}
